class Solution {
public:
  vector<vector<string>> groupAnagrams(vector<string>& strs) {

    vector<vector<string>> ans;
    map<string, int> m;
    int index = 0;

    for(string &s : strs){
      string t = s;
      sort(t.begin(), t.end());
      if(!m.count(t)){
        m[t] = index;
        ans.push_back(*(new vector<string>()));
        ans[index].push_back(s);
        ++index;
      }else{
        ans[m[t]].push_back(s);
      }
    }

    return ans;

  }
};